﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;

namespace AtlasWebApp
{
    public partial class FlagUploader : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ButtonUploadFlag_OnClick(object sender, EventArgs args)
        {
            try
            {
                byte[] bytes = File.ReadAllBytes(this.TextBoxFilePath.Text);
                using (AtlasEntities context = new AtlasEntities())
                {
                    Flag flag = new Flag();
                    flag.FlagContent = bytes;
                    context.Flags.AddObject(flag);
                    context.SaveChanges();

                    this.LiteralInfo.Text = "Uploaded successfully: Id = " + flag.FlagId.ToString();
                }
            }
            catch (Exception ex)
            {
                this.LiteralInfo.Text = "Failed to upload flag.";
            }
        }
    }
}